<template>
<el-table
    v-loading="loading"
    :data="tableData"
    style="width: 100%">
</el-table>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import { setToken } from '@/utils/auth'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    
    data() {
        return {
            // table结构
            columns: [],
            // 接口地址
            api: {
                index: `/admin/middleground/index`,
                find: `/admin/middleground/find`,
                add: `/admin/middleground/add`,
                edit: `/admin/middleground/edit`,
                delete: `/admin/middleground/delete`,
                export: `/admin/middleground/export`,
                status: `/admin/middleground/status`
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: false,
            // 查询参数
            queryParams: {

            },
            tableData: [],
            loading: true
        }
    },
    created () {
        this.Middleground()
    },
    watch: {
        
    },
    methods: {
        // 编辑
        Middleground() {
            let get_adminid = 0
            let get_type = 0
            if(this.$route.query.adminid == '' || this.$route.query.adminid == undefined){
                get_adminid = 0
            }else{
                get_adminid = this.$route.query.adminid;
            }
            if(this.$route.query.type == '' || this.$route.query.type == undefined){
                get_type = 0
            }else{
                get_type = this.$route.query.type;
            }
            this.get_middleground(get_adminid,get_type);
        },

        // 编辑回显
        async get_middleground(adminid,type) {
            let response = await this.request.get(this.api.index, { params: { id: adminid,type: type } })
            if(response.date == 1){//参数错误
                this.$message.error(response.msg);
                setTimeout(() => {
                    var userAgent = navigator.userAgent;
                        if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1)	{
                        window.open('','_self').close()  
                        window.location.href = "about:blank"
                    }else {
                        window.opener = null;
                        window.open("about:blank", "_self");
                        window.close();
                    }
                }, 3000)
            }else if(response.date == 2){
                setToken(response.msg)
                this.$router.push('/index');
            }else if(response.date == 3){
                setToken(response.msg)
                this.$router.push('/index');
            }else if(response.date == 4){
                this.$message.success('已登录');
                setTimeout(() => {
                    this.$router.push('/index');
                }, 1000)
            }else{
                this.$message.error('系统错误');
                setTimeout(() => {
                    var userAgent = navigator.userAgent;
                        if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1)	{
                        window.open('','_self').close()  
                        window.location.href = "about:blank"
                    }else {
                        window.opener = null;
                        window.open("about:blank", "_self");
                        window.close();
                    }
                }, 3000)
            }
        },
        
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
